package controller;

import java.util.List;

import com.jfinal.core.Controller;

import model.User;
/**
 * 处理用户数据增删改查
 */
public class UserController extends Controller {
	public void index() {
		List<User> users = User.dao.find("select * from user");
		setAttr("users",users);
		System.out.println("得到数据"+users.size()+"个");
		render("list.jsp");
	}

	public void form() {
		Integer id = getParaToInt(0);
		if(id==null||id>0)
		{
			setAttr("user",User.dao.findById(id));
		}
		render("form.jsp");
	}
	/**
	 * 数据提交
	 */
	public void submit(){
		User user=getModel(User.class,"user");
		user.save();
		redirect("/user"); 
	}
	
	public void update(){
		User user=getModel(User.class,"user");
		user.update();
		redirect("/user"); 
	}
	
	public void edit(){
		form();
	}
	
	public void del(){
		User.dao.deleteById(getPara(0));
		redirect("/user"); 
	}
}
